package com.zlf.sb.demo.design.chain;

// 具体处理者，结合策略
public class RequestHandlerImpl implements RequestHandler {
    private RequestStrategy strategy; // 策略
    private RequestHandler nextHandler; // 下一个处理者

    public RequestHandlerImpl(RequestStrategy strategy) {
        this.strategy = strategy;
    }

    @Override
    public void setNextHandler(RequestHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public void handleRequest(UserRequest request) {
        // 策略处理
        strategy.process(request);
        // 将请求传递给下一个处理者
        if (nextHandler != null) {
            nextHandler.handleRequest(request);
        }
    }
}